import { getCache, setCache } from '@/utils/session';
const state = {
    open: true,
    fixHeader: getCache('FIX_HEARDER') == null ? true : getCache('FIX_HEARDER'),
    tagShow: getCache('TAG_SHOW') == null ? true : getCache('TAG_SHOW'),
    settingVisible: false,
    initSetting: process.env.NODE_ENV === 'development',
    layout: getCache('LAYOUT') || 'vertical',
    theme: getCache('THEME') || 'blue',
    isAudio: false,
    isLoading:false,//全局加载
};

const mutations = {
    TOGGLE_OPEN(state) {
        state.open = !state.open;
    },
    CHANGE_SETTING(state, { key, value, cache }) {
        // eslint-disable-next-line
        if (state.hasOwnProperty(key)) {
            state[key] = value;
            setCache(cache, value);
        }
    },
    CHANGE_VISIBLE(state, bool) {
        state.settingVisible = bool;
    },
    OPEN_AUDIO(state, bool) {
        state.isAudio = bool;
    },
    CHANGE_SPIN(state,bool){
        state.isLoading = bool
    }
};

const actions = {
    changeSetting({ commit }, setting) {
        commit('CHANGE_SETTING', setting);
    },
    changeVisible({ commit }, bool) {
        commit('CHANGE_VISIBLE', bool);
    },
    changeOpenAudio({ commit }, bool) {
        commit('OPEN_AUDIO', bool);
    },
    changeSpin({commit},bool){
        commit('CHANGE_SPIN',bool)
    }
};

export default {
    namespaced: true,
    state,
    mutations,
    actions
};
